package com.library.guard.core.config;

import com.library.common.utils.uuid.UUID;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.servlet.http.HttpSession;
import javax.websocket.Extension;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.List;
import java.util.Map;


/**
 * @Package: com.library.guard.core.config
 * @ClassName: WsConfig
 * @Author: Yin
 * @Date: 15:52
 * @Description: 此文件描述信息
 */
@Component
public class GuardServerEndpointConfig extends ServerEndpointConfig.Configurator {

    /**
     * 重写第一次握手
     * @param sec 服务器websocket端点的配置
     * @param request
     * @param response
     */
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {
        HttpSession httpSession =(HttpSession) request.getHttpSession();
        Map<String, Object> properties = sec.getUserProperties();
        // 唯一标识
        String sessionKey = UUID.randomUUID().toString(true);
        properties.put(N01Config.WS_CONNECTED,sessionKey);

    }

}
